using System;
using System.Drawing;

namespace TicTacToe.Opponents
{
    internal static class OpponentHelpers
    {
        internal static Point PickRandomEmptySpace(Board board)
        {
            if (board.IsFull())
                throw new ArgumentException("Unable to choose a space because the board is full.");

            var random = new Random();
            Func<Point> pickSpace = () => new Point(random.Next(0, board.Size), random.Next(0, board.Size));

            while (true)
            {
                var attempt = pickSpace();
                if (!board.GetValue(attempt).HasValue)
                    return attempt;
            }
        }
    }
}